﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeJC.DAL.Model;

namespace DeJC.BLL.Managers {
    public static class UserManager {
        public static IEnumerable<User> GetUsers() {
            IEnumerable<User> users;
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                users=unitOfWork.UserRepository.GetAll();
            }
            return users;
        }

        public static bool AddUser(User user) {
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                unitOfWork.UserRepository.Add(user);
                unitOfWork.Save();
            }
            return true;
        }

         public static bool UpdateUser(User user)
         {
             using (UnitOfWork unitOfWork = new UnitOfWork())
             {
                 unitOfWork.UserRepository.Update(user);
                 unitOfWork.Save();
             }
             return true;
         }

        public static bool DeleteUser(int id) {
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                User user=unitOfWork.UserRepository.GetById(id);
                //unitOfWork.UserRepository.Delete(user);
                user.Deleted = true;
                user.DeletedDate = DateTime.Now;
                unitOfWork.Save();
            }
            return true;
        }

        // public List<User> GetUserPaged(int page, int rows, out int totalCount)
        // {
        // List<User> users;
        // using (UnitOfWork unitOfWork = new UnitOfWork())
        // {
        // users = unitOfWork.UserRepository.GetUserPaged
        // (page, rows, out totalCount);
        // }
        // return users;
        // }
        public static User GetById(int id) {
            User user;
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                user=unitOfWork.UserRepository.GetById(id);
            }
            return user;
        }

        public static User GetByUserName(string userName)
        {
            User user;
            using(UnitOfWork unitOfWork= new UnitOfWork())
            {
                user = unitOfWork.UserRepository.GetUser(userName);
            }
            return user;
        }
    }
}
